package com.blog.service.frontpage;

import java.util.List;

import com.blog.dao.frontpage.PersoncenterDao;
import com.blog.entity.ArticleCountEntity;
import com.blog.entity.ArticleDetailEntity;
import com.blog.entity.BlogPostEntity;
import com.blog.entity.BolgerArticleEntity;
import com.blog.entity.CommentContentEntity;
import com.blog.entity.DiscussEntity;
import com.blog.entity.DraftEntity;
import com.blog.entity.PersonalcenterDetailEntity;
import com.blog.entity.UserEntity;
import com.blog.entity.UserUrlEntity;
import com.blog.utils.Util;
/**
 * 个人中心页面服务层
 * @author song
 *
 */
public class PersonalCenterService {
	private static PersonalCenterService instance;
	private PersonalCenterService() {
		
	}
	public static synchronized PersonalCenterService getInstance() {
		if(instance==null) {
			instance=new PersonalCenterService();
		}
		return instance;
	}
	PersoncenterDao dao=PersoncenterDao.getInstance();
	private Util util=new Util();
	/**
	 * 1.根据作者id查询文章信息
	 */
	public List<BolgerArticleEntity> getArticleEntity(Integer id,int start,int length){
		List<BolgerArticleEntity> ist=dao.getArticleInfoByWriterId(id,start,length);
		String temp="";
		for(BolgerArticleEntity e:ist) {
			temp=Util.removeTag(e.getArticle_content());
			if(temp.length()>200) {
				e.setArticle_content(temp.substring(0, 200));
			}
		}
		
		return ist;
	}
	/**
	 * 2.将文章保存到数据库
	 */
	public void saveBlog(BlogPostEntity post) {
		dao.saveBlog(post);
	}
	/**
	 * 3.根据作者id查询草稿箱
	 */
	public List<DraftEntity> getDraftById(Integer id){
		return dao.getDraftById(id);
	}
	/*
	 * 4.根据作者id查询草稿箱文章的详细信息
	 */
	public PersonalcenterDetailEntity getBlogDetail(Integer id,Integer writerid,int status){
		return dao.getBlogDetail(id,writerid,status);
	}
	/**
	 * 5.根据id查询博客文章
	 */
	public ArticleCountEntity getTotalNum(Integer id,Integer status) {
		return dao.getTotalNum(id, status);
	}
	/**
	 * 6.根据id删除博客
	 */
	public void deleteBlogById(int id) {
		dao.deleteBlogById(id);
	}
	/**
	 * 7.更新用户信息
	 */
	public void updateUserInfo(String field,String value,int id) {
		dao.updateUserInfo(field, value, id);
	}
	/**
	 * 8.根据用户id查询博客
	 */
	public UserEntity getUserInfo(int id) {
		return dao.getUserInfo(id);
	}
	/**
	 * 9.获取用户头像url
	 */
	public UserUrlEntity getUserUrl(int id) {
		return dao.getUserUrl(id);
	}
	/**
	 * 10.保存用户url
	 */
	public void saveHeadPic(String url,int id) {
		dao.saveHeadPic(url, id);
	}
	/**
	 * 11.获得文章信息
	 */
	public ArticleDetailEntity getArticleInfo(int id,int writerid){
		return dao.getArticleInfo(id,writerid);
	}
	/**
	 * 12.获得评论信息
	 */
	public List<CommentContentEntity> getComentById(int articleid){
		return dao.getComentById(articleid);
	}
	/**
	 * 13.保存评论
	 */
	public void saveComent(DiscussEntity e) {
		dao.save(e);
	}
	/**
	 * 4.根据作者id查询发表博客
	 */
	public List<DraftEntity> getPostBlogById(Integer id){
		return dao.getPostBlogById(id);
	}
}
